home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / DockStrip / StubCommon.c < prev   
Encoding:
C/C++ Source or Header  |  2000-06-24  |  7.4 KB  |  267 lines

  1. #include <LowMem.h>
  2. #include <ControlStrip.h>
  3. #include <DCon.h>
  4.  
  5. #include "DockStrip.h"
  6.  
  7.  
  8. static    Boolean moduleHandlesIdleDelay = true;
  9. static    RgnHandle wideRgn = nil;
  10. static    RgnHandle alreadySaved = nil;
  11.  
  12. unsigned long BeforeModule (
  13.     SDockStripGlobals* globals,
  14.     UInt32    index,
  15.     unsigned long message,
  16.     Handle prefsHandle,
  17.     Rect* statusRect,
  18.     GrafPtr statusPort,
  19.     Boolean* runModule)
  20. {
  21.     UInt32 iindex;
  22.     
  23.     if (wideRgn == nil) {
  24.         Rect rect = {-32768, -32768, 32767, 32767};
  25.         wideRgn = NewRgn ();
  26.         RectRgn (wideRgn, &rect);
  27.     }
  28.     
  29.     globals -> someRunning = false;
  30.     for (iindex = 0; iindex < StubListSize; iindex++) {
  31.         if (globals -> moduleList [iindex].stub.handle != nil) {
  32.             if ((globals -> moduleList [iindex].goingUp) || (globals -> moduleList [iindex].amountWider != 0)) {
  33.                 globals -> someRunning = true;
  34.                 break;
  35.             }
  36.         }
  37.     }
  38.     
  39.     if (globals -> lastUpdate + 60 < LMGetTicks ()) {
  40.         globals -> needUpdate = true;
  41.     }
  42.  
  43.     if (globals -> someRunning) {
  44.         globals -> needUpdate = true;
  45.     } else if (globals -> needUpdate) {
  46.         GrafPtr    srcP = (GrafPtr) &globals -> ourPort;
  47.         GrafPtr    destP = (GrafPtr) globals -> updatePort;
  48.         Rect    src = {-200, 0, 0, 1024};
  49.         LocalToGlobal (&topLeft (src));
  50.         LocalToGlobal (&botRight (src));
  51.         
  52.         CopyRgn (wideRgn, destP -> visRgn);
  53.         SetClip (wideRgn);
  54.         SetPort (destP);
  55.  
  56.         dprintf ("Noone running - updating\n");
  57.         
  58.         CopyBits (&srcP -> portBits, &destP -> portBits, &src, &src, srcCopy, nil);
  59.         globals -> needUpdate = false;
  60.         globals -> lastUpdate = LMGetTicks ();
  61.     }
  62.  
  63.     SetPort ((GrafPtr) globals -> offscreenGWorld);
  64.  
  65.     if (message == sdevDrawStatus) {
  66.         Rect        erase = *statusRect;
  67.         RGBColor    saveBack;
  68.         RGBColor    gray = {0xC000, 0xC000, 0xC000};
  69.         GetBackColor (&saveBack);
  70.         RGBBackColor (&gray);
  71.         
  72.         InsetRect (&erase, -10, -10);
  73.         EraseRect (&erase);
  74.         RGBBackColor (&saveBack);
  75.         // fix the rect
  76.         statusRect->right -= globals -> moduleList [index].amountWider;
  77.     }
  78.     
  79.     if (message == 9) {
  80. //        dprintf ("Handling message 9 for %d\n", index);
  81.         *runModule = false;
  82.         return 1;
  83.     }
  84.         
  85.     *runModule = true;
  86.     return 0;
  87. }
  88.  
  89.  
  90. long AfterModule (
  91.     SDockStripGlobals* globals,
  92.     UInt32    index,
  93.     unsigned long message,
  94.     Handle prefsHandle,
  95.     Rect* statusRect,
  96.     GrafPtr statusPort,
  97.     long result)
  98. {
  99.  
  100. //    if (index <= 4) {
  101. //        dprintf ("Message %d to %d: returned %d, ", message, index, result);
  102. //    }
  103.  
  104.     switch (message) {
  105.         case sdevGetDisplayWidth: {
  106.             Boolean newGoingUp;
  107.             Point    mouse = LMGetMouseLocation ();
  108.             Rect    iconRect = (*(statusPort -> clipRgn)) -> rgnBBox;
  109.             
  110.             if (result <= 0)    
  111.                 result = 25;
  112.                 
  113.             CallSetPortProc (globals -> saveSetPort, statusPort);
  114. //            SetPort (statusPort);
  115.             GlobalToLocal (&mouse);
  116.             iconRect.top -= iconRect.right - iconRect.left;
  117.             iconRect.bottom += iconRect.right - iconRect.left;
  118.             newGoingUp = PtInRect (mouse, &iconRect);
  119. /*            if (newGoingUp)
  120.                 result *= 2;*/
  121.             if (!globals -> moduleList [index].goingUp && newGoingUp)
  122.                 globals -> moduleList [index].startingUp = true;
  123.             else
  124.                 globals -> moduleList [index].startingUp = false;
  125.             globals -> moduleList [index].goingUp = newGoingUp;
  126.             
  127.             if (globals -> moduleList [index].goingUp) {
  128.                 if ((globals -> moduleList [index].amountWider + result) < (result * kMagnificationFactor)) {
  129.                     int difference = (result * kMagnificationFactor) - 
  130.                                         (globals -> moduleList [index].amountWider + result);
  131.                     int increment = difference > 1 ? difference/2 : 1;
  132.                     globals -> moduleList [index].amountWider += increment;
  133.                 }
  134.             } else {
  135.                 if (globals -> moduleList [index].amountWider > 0) {
  136.                     int difference = (result * kMagnificationFactor) - 
  137.                                         (globals -> moduleList [index].amountWider + result);
  138.                     int increment = difference > 1 ? difference/2 : 1;
  139.  
  140.                     globals -> moduleList [index].amountWider -= increment;
  141.                     if (globals -> moduleList [index].amountWider < 0)
  142.                         globals -> moduleList [index].amountWider = 0;
  143.                 }
  144.             }
  145.             result += globals -> moduleList [index].amountWider;
  146.  
  147.             /* Bogon strip returns negative widths */
  148.             globals -> moduleList [index].width = result;
  149.             
  150.             break;
  151.         }
  152.             
  153.         case 9:
  154.             dprintf ("Index %d got message 9 and returned %d\n", index, result);
  155.             break;
  156.         
  157.         case sdevFeatures:
  158.             if ((result & 0x10) == 0) {
  159.                 result |= 0x10;
  160.                 moduleHandlesIdleDelay = false;
  161.             }
  162.             break;
  163.                     
  164.         case sdevPeriodicTickle:
  165.             result |= 1 << sdevResizeDisplay;
  166.             break;
  167.             
  168.         case sdevDrawStatus: {
  169.             Rect    srcRect = *statusRect;        
  170.             Rect    destRect = *statusRect;
  171.             Rect    updateRect;
  172.             Rect    curRect;
  173.             
  174.             GrafPtr    savePort;
  175.             GrafPtr srcPort;
  176.             GrafPtr destPort;
  177.             
  178. //            RgnHandle destRgn = NewRgn (), saveRgn = NewRgn (), updateRgn = NewRgn (), justAboveRgn = NewRgn ();
  179. //            Rect justAbove;
  180.             
  181.             GetPort (&savePort);
  182.  
  183.             srcRect = *statusRect;
  184.             destRect = *statusRect;
  185.  
  186.             destRect.right += globals -> moduleList [index].amountWider;
  187.             destRect.top = destRect.bottom - (srcRect.bottom - srcRect.top) * (destRect.right - destRect.left) / (srcRect.right - srcRect.left);
  188.             
  189. //            justAbove = destRect;
  190. //            justAbove.bottom = 0;
  191.  
  192.             updateRect = destRect;
  193.             updateRect.bottom = 0;
  194.             updateRect.left -= 2;
  195.             updateRect.right += 40;
  196.             updateRect.top -= 40;            
  197.  
  198.             CallSetPortProc (globals -> saveSetPort, statusPort);
  199.             LocalToGlobal (&topLeft(destRect));
  200.             LocalToGlobal (&botRight(destRect));
  201.             LocalToGlobal (&topLeft(updateRect));
  202.             LocalToGlobal (&botRight(updateRect));
  203. //            LocalToGlobal (&((Point*)(&justAbove))[0]);
  204. //            LocalToGlobal (&((Point*)(&justAbove))[1]);
  205.  
  206.             /* Before drawing the bigger status to the screen, copy out the data already there */
  207. /*            if (alreadySaved == nil) {
  208.                 alreadySaved = NewRgn ();
  209.             }
  210.             if (globals -> moduleList [index].startingUp) {
  211.                 RectRgn (alreadySaved, &destRect);
  212.             }
  213.             
  214.             RectRgn (destRgn, &destRect);
  215.             RectRgn (justAboveRgn, &justAbove);
  216.             DiffRgn (destRgn, alreadySaved, saveRgn);
  217.             SectRgn (saveRgn, justAboveRgn, saveRgn);
  218.             
  219.             srcPort = (GrafPtr) &globals -> ourPort;
  220.             destPort = (GrafPtr) globals -> updatePort;
  221.             CallSetPortProc (globals -> saveSetPort, destPort);
  222.             CopyRgn (wideRgn, destPort -> visRgn);
  223.             SetClip (wideRgn);
  224.             CopyBits (&srcPort -> portBits, &destPort -> portBits, &(*saveRgn)->rgnBBox, &(*saveRgn)->rgnBBox, srcCopy, saveRgn);
  225.             
  226.             UnionRgn (alreadySaved, saveRgn, alreadySaved);
  227.             
  228.             DiffRgn (alreadySaved, destRgn, updateRgn);
  229.             SectRgn (updateRgn, justAboveRgn, updateRgn);
  230.             
  231.             destPort = (GrafPtr) &globals -> ourPort;
  232.             srcPort = (GrafPtr) globals -> updatePort;
  233.             CallSetPortProc (globals -> saveSetPort, destPort);
  234.             CopyRgn (wideRgn, destPort -> visRgn);
  235.             SetClip (wideRgn);
  236.             CopyBits (&srcPort -> portBits, &destPort -> portBits, &(*updateRgn)->rgnBBox, &(*updateRgn)->rgnBBox, srcCopy, updateRgn);
  237.             
  238.             DisposeRgn (destRgn);
  239.             DisposeRgn (saveRgn);
  240.             DisposeRgn (updateRgn);
  241.             DisposeRgn (justAboveRgn);*/
  242.  
  243.             srcPort = (GrafPtr) globals -> updatePort;
  244.             destPort = (GrafPtr) &globals -> ourPort;
  245.             CallSetPortProc (globals -> saveSetPort, destPort);
  246.             CopyRgn (wideRgn, destPort -> visRgn);
  247.             SetClip (wideRgn);
  248.             CopyBits (&srcPort -> portBits, &destPort -> portBits, &updateRect, &updateRect, srcCopy, nil);
  249.             
  250.             /* Draw the updated frob */
  251.             srcPort = (GrafPtr) globals -> offscreenGWorld;
  252.             destPort = (GrafPtr) &globals -> ourPort;
  253.             CallSetPortProc (globals -> saveSetPort, destPort);
  254.             CopyBits (&srcPort -> portBits, &destPort -> portBits, &srcRect, &destRect, srcCopy, nil);
  255.             SetPort (savePort);
  256.             
  257.             break;
  258.         }
  259.     }
  260.         
  261. //    if (index <= 4){
  262. //        dprintf ("actually returned %d\n", result);
  263. //    }
  264.  
  265.     return result;
  266. }
  267.